package onki.tests.pageObjects;
import java.util.List;
import java.util.ArrayList;
import org.openqa.selenium.support.*;
import org.openqa.selenium.*;

/**
 * A Page Object for a single ONKI Light concept page. Keeps all the elements
 * easily findable for testing.
 *
 */
public class OnkiConceptPageObject {

  protected WebDriver driver;
  @FindBy(className = "jstree-open")
  private WebElement hierarchyList;
  @FindBy(className = "prefLabel")
  private WebElement prefLabel;
  @FindBy(className = "crumb-path")
  private WebElement breadCrumbContainer;
  @FindBy(className = "expand-crumbs")
  private WebElement breadCrumbExpansion;
  @FindBy(className = "rdftype")
  private WebElement type;
  
  public OnkiConceptPageObject(WebDriver driver) {
    this.driver = driver;
  }

  public String getPrefLabel() {
    return this.prefLabel.getText();
  }
  
  public String getType() {
    return this.type.getText();
  }
  
  private void breadCrumbExpansion() {
    this.breadCrumbExpansion.click();
  }

  public ArrayList<String> getHierarchyLabels() {
    ArrayList<String> hierarchyLabels = new ArrayList();
    List<WebElement> li = hierarchyList.findElements(By.xpath(".//a"));
    for (WebElement concept : li) {
      concept.getAttribute("href");
    }
    return hierarchyLabels;
  }
  
  public ArrayList<String> getBreadCrumbLabels() {
    breadCrumbExpansion();
    ArrayList<String> breadCrumbLabels = new ArrayList();
    List<WebElement> crumbPath = breadCrumbContainer.findElements(By.xpath(".//a"));
    for (WebElement concept : crumbPath) {
      breadCrumbLabels.add(concept.getText());
    }
    return breadCrumbLabels;
  }
  
  
}
